<template>
  <default-layout>
    <header-back text="我的缴费" slot="header"></header-back>
    <div
      v-infinite-scroll="loadMore"
      infinite-scroll-disabled="disabledScroll"
      infinite-scroll-distance="10"
      infinite-scroll-immediate-check="false"
      slot="main"
      class="scroll-view">
      <mt-navbar v-model="selected">
        <mt-tab-item id="00">党员缴费</mt-tab-item>
        <mt-tab-item id="01">继续教育报名费</mt-tab-item>
      </mt-navbar>
      <div class="list">
        <div class="item" @click="payWaiting(val)" v-for="(val, key) in list" :key="key">
          <div class="top">
            <div class="top-left" v-if="selected === '00'">
              <i class="xffont xf-dangfeijiaona"></i>
            </div>
            <div class="top-mid">
              <span class="tit">{{val.name}}</span>
              <span class="desc">{{$dateFormat(val.createDate).format('YYYY-MM-DD HH:mm')}}</span>
            </div>
            <div class="top-right">￥{{val.totalFee}}</div>
          </div>
          <div class="bottom">
            <span class="bottom-left">订单号：{{val.orderNumber}}</span>
          </div>
          <div class="action">
            <span :class="Number(val.status) === 1 ? 'primary' : Number(val.status) === 0 ? 'danger' : ''">{{val.state}}</span>
            <!--<div v-if="Number(val.status) === 1">-->
              <!--<mt-button size="small" @click.prevent.stop="invoice(val)">开发票</mt-button>-->
            <!--</div>-->
            <div v-if="Number(val.status) === 0">
              <!--未缴费-->
              <mt-button size="small" plain @click.prevent.stop="cancel(val)">订单取消</mt-button>
              <mt-button type="primary" size="small" @click.prevent.stop="pay(val)">去支付</mt-button>
            </div>
          </div>
        </div>
      </div>
      <loading-text v-if="loading"></loading-text>
      <finish-text v-if="noMore"></finish-text>
      <empty v-if="empty"></empty>
      <yd-backtop></yd-backtop>
    </div>
    <transition name="router" mode="out-in">
      <router-view class="fixed-router"></router-view>
    </transition>
  </default-layout>
</template>
<script>
  import HeaderBack from '../../../components/header-back/header-back.vue'
  import LoadingText from '../../../components/loading-text/loading-text.vue'
  import FinishText from '../../../components/finish-text/finish-text.vue'
  import DefaultLayout from '../../../layouts/default-layout/default-layout'
  import {infinite} from '../../../common/js/mixin'
  import Empty from '../../../components/empty/empty'
  import {mapMutations} from 'vuex'

  export default {
    components: {
      Empty,
      DefaultLayout,
      FinishText,
      LoadingText,
      HeaderBack},
    data() {
      return {
        selected: '00',
        /* 以下五个参数为上拉加载页面必需的参数 */
        loading: true,
        page: 1,
        size: 10,
        total: 0,
        list: []
        /* 以上五个参数为上拉加载页面必需的参数 */
      }
    },
    computed: {
      ...infinite
    },
    methods: {
      ...mapMutations({
        setOrder: 'SET_ORDER'
      }),
      cancel(val) {
        this.$message.confirm('确定取消订单？').then(() => {
          this.$post('/admin/person/sapi/person/center/my/payment/orderCancel', {
            orderNumber: val.orderNumber
          }, loading => { this.$message.loading(loading) }).then(res => {
            this.$message.toast(res.message)
            this.page = 1
            this.loadMore()
          })
        })
      },
      pay(val) {
        this.setOrder(val)
        this.$router.push({
          name: 'payWay',
          query: {
            type: this.selected === '00' ? 'party' : 'education'
          }
        })
      },
      payWaiting(val) {
        const status = Number(val.status)
        this.setOrder(val)
        if (status === 0) {
          this.$router.push({
            name: 'myPayWaiting',
            query: {
              type: this.selected === '00' ? 'party' : 'education'
            }
          })
        } else {
          this.$router.push({
            name: 'myPayRecord',
            query: {
              type: this.selected === '00' ? 'party' : 'education'
            }
          })
        }
      },
      handleItem() {
        this.$router.push({name: 'myPayRecord'})
      },
      // invoice(val) {
      //   // 开发票
      // },
      loadMore() {
        if (this.page === 1) this.list = []
        this.$post('/admin/person/sapi/person/center/my/payment/list', {
          page: this.page,
          pageSize: this.size,
          type: this.selected // 查询类型（00 党员缴费，01 继续教育报名费）
        }, loading => {
          this.loading = loading
        }, false).then(res => {
          this.list = this.list.concat(res.data.dataList)
          this.total = res.data.pageBean.totalCount
          this.page++
        })
      }
    },
    created() {
      this.selected = this.$route.params.id
      this.loadMore()
      this.$watch('selected', () => {
        setTimeout(() => {
          this.page = 1
          this.loadMore()
        }, 20)
      })
    }
  }
</script>
<style lang="scss" scoped>
  @import "../../../common/style/variable";
  .item{
    background: #fff;
    margin: .15rem 0 0 0;
    display: block;
    .top{
      padding: .2rem;
      border-bottom: 1px solid #ededed;
      display: flex;
      align-items: center;
      .top-left{
        padding: 0 .2rem 0 0;
        .xf-dangfeijiaona{
          font-size: .8rem;
          color: $primary;
        }
      }
      .top-mid{
        flex: 1;
        display: flex;
        flex-direction: column;
        .tit{
          font-size: .32rem;
          margin: 0 0 .1rem 0;
        }
        .desc{
          font-size: .3rem;
          color: #666;
        }
      }
      .top-right{
        font-size: .4rem;
        font-weight: bold;
        color: $danger;
      }
    }
    .bottom{
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: .2rem;
      .bottom-left{
        font-size: .28rem;
        color: #666;
      }
    }
  }
  .action{
    padding: .2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #ededed;
  }
  .warn{
    background: $warning;
    color: #fff;
  }
  .xf-jiaoyu-copy{
    color: #f2ba46;
    font-size: .7rem;
  }
  .primary{
    color: $primary;
  }
  .danger{
    color: $danger;
  }
</style>
